package com.campus.counseling.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.campus.counseling.model.common.Result;
import com.campus.counseling.model.dto.TestRecordDTO;
import com.campus.counseling.model.dto.TestResultDTO;
import com.campus.counseling.model.query.TestRecordQuery;
import com.campus.counseling.model.vo.TestResultVO;
import com.campus.counseling.service.TestRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "测试记录管理")
@RestController
@RequestMapping("/api/test-records")
@RequiredArgsConstructor
public class TestRecordController {

    private final TestRecordService testRecordService;

    @Operation(summary = "分页查询测试记录")
    @GetMapping("/page")
    public Result<Page<TestResultVO>> getRecordPage(TestRecordQuery query) {
        return Result.success(testRecordService.getRecordPage(query));
    }

    @Operation(summary = "获取测试记录详情")
    @GetMapping("/{id}")
    public Result<TestResultVO> getRecord(@PathVariable Long id) {
        return Result.success(testRecordService.getResultById(id));
    }

    @Operation(summary = "提交测试记录")
    @PostMapping
    public Result<Long> submitRecord(@RequestBody TestRecordDTO dto) {
        return Result.success(testRecordService.submitRecord(dto));
    }

    @Operation(summary = "评审测试记录")
    @PostMapping("/{id}/review")
    public Result<Void> reviewRecord(@PathVariable Long id, @RequestBody TestResultDTO dto) {
        testRecordService.review(id, dto);
        return Result.success();
    }

    @Operation(summary = "获取测试答题记录")
    @GetMapping("/{id}/answers")
    public Result<Map<String, Object>> getAnswerRecord(@PathVariable Long id) {
        return Result.success(testRecordService.getAnswerRecord(id));
    }
} 